
//
//  GuangXiangViewController.m
//  ShangChengMoBan
//
//  Created by yaoqi yaoqi on 16/11/1.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "GuangXiangViewController.h"

@interface GuangXiangViewController ()<UIWebViewDelegate>
@property(nonatomic,strong)NSTimer *paintingTimer;
@end

@implementation GuangXiangViewController
{
    int _page;
    UILabel * _la;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _page = 3;
    [self drawNavWithTitle:@"广告列表" WithColor:[UIColor colorWithHue:0.00 saturation:0.00 brightness:1.00 alpha:1.00]];
    [self drawBackButton];
    UIWebView * web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, KScreenWidth, KScreenHeight-64)];
    web.delegate = self;
    [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://item.taobao.com/item.htm?spm=a219r.lm895.14.1243.flf87V&id=538495451698&ns=1&abbucket=9&sku=1627207:28327#detail"]]];
    [self.view addSubview:web];
    _la = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth-50, 15+64, 35, 35)];
    _la.layer.cornerRadius = 35/2;
    _la.layer.masksToBounds = YES;
    _la.layer.borderColor = [UIColor whiteColor].CGColor;
    _la.layer.borderWidth = 3;
    _la.backgroundColor = [UIColor lightGrayColor];
    _la.alpha = 0.7;
    _la.textAlignment = NSTextAlignmentCenter;
    _la.text = @"3";
    [self.view addSubview:_la];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    [self startPainting];
}
-(void)paint{
    if (_page == 0) {
        [self stopPainting];
        [_la removeFromSuperview];
    }
    _page--;
    _la.text = [NSString stringWithFormat:@"%d",_page];
    
}
// 开始定时器

- (void) startPainting{
     self.paintingTimer = [NSTimer scheduledTimerWithTimeInterval:1
                          
                                                          target:self
                          
                                                        selector:@selector(paint)  userInfo:nil
                          
                                                         repeats:YES];
    
    
    
    // 当需要调用时,可以把计时器添加到事件处理循环中
    
    [[NSRunLoop currentRunLoop] addTimer:self.paintingTimer forMode:NSDefaultRunLoopMode];
    
    
    
}


// 停止定时器

- (void) stopPainting{
    
    if (self.paintingTimer != nil){
        
        // 定时器调用invalidate后，就会自动执行release方法。不需要在显示的调用release方法
        
        [self.paintingTimer invalidate];
        
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
